package com.brspace.qualitycontrol.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.brspace.qualitycontrol.entity.ProcessRouter;
import com.brspace.qualitycontrol.mapper.ProcessRouterMapper;
import com.brspace.qualitycontrol.service.ProcessRouterService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.brspace.qualitycontrol.utils.ServiceException;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-04-02
 */
@Service
public class ProcessRouterServiceImpl extends ServiceImpl<ProcessRouterMapper, ProcessRouter> implements ProcessRouterService {
    /**
     *@Description 保存
     *@Params [router]
     *@author Hugo
     *@date 2021-03-23 16:58
     *@return null
     **/
    @Override
    public void saveRouter(ProcessRouter router) {
        if ("".equals(router.getName())){
            throw new ServiceException("请输入路由名称");
        }
        Map<String,Object> map = new HashMap<>(16);
        map.put("p_id",router.getPId());
        map.put("current_id",router.getCurrentId());
        map.put("target_id",router.getTargetId());
        map.put("name",router.getName());
        if (baseMapper.selectList(new QueryWrapper<ProcessRouter>().allEq(map,false)).size() >0){
            throw new ServiceException("路由已存在");
        }
        baseMapper.insert(router);
    }
}
